<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div id="app">
        <table border="1">
            <thead>
                <tr>
                    <th>名称</th>
                    <th>单价</th>
                    <th>数量</th>
                    <th>小计</th>
                </tr>
            </thead>
            <tbody>
                <tr>
                    <td>{{list[0].name}}</td>
                    <td>¥{{list[0].price}}元</td>
                    <td>
                        <input type="text" v-model="list[0].num">
                    </td>
                    <td>¥{{list[0].price * list[0].num}}元</td>
                </tr>
                <tr>
                    <td>{{list[1].name}}</td>
                    <td>¥{{list[1].price}}元</td>
                    <td>
                        <input type="text" v-model="list[1].num">
                    </td>
                    <td>¥{{list[1].price * list[1].num}}元</td>
                </tr>
                <tr>
                    <td>{{list[2].name}}</td>
                    <td>¥{{list[2].price}}元</td>
                    <td>
                        <input type="text" v-model="list[2].num">
                    </td>
                    <td>¥{{list[2].price * list[2].num}}元</td>
                </tr>
                <tr>
                    <td colspan="2">总计</td>
                    <td>{{totalNum}}件</td>
                    <td>{{totalPrice()}}元</td>
                </tr>
            </tbody>
        </table>
    </div>
    <script src="../vue.js"></script>
    <script>
        let vm = new Vue({
            el: '#app',
            data: {
                list: [
                    {name: '手机', price: 4000, num: 3},
                    {name: '电脑', price: 6000, num: 1},
                    {name: '平板', price: 2000, num: 5},
                ]
            },
            computed: {
                // 总数量
                totalNum() {
                    let num = 0;
                    for (let index = 0; index < this.list.length; index++) {
                        num += this.list[index].num * 1
                    }
                    return num
                }
            },
            methods: {
                totalPrice() {
                    let num = 0;
                    for (let index = 0; index < this.list.length; index++) {
                        num += this.list[index].num * this.list[index].price
                    }
                    return num
                }
            }
        })
    </script>
</body>
</html>